package com.ware4u.fx.news.controller;


import com.ware4u.fx.news.dao.CatalogRepository;
import com.ware4u.fx.news.entity.Catalog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Tag(name = "CatalogController", description = "板块接口")
@RequestMapping(value = "/api/catalog")
public class CatalogController {

    @Autowired
    private CatalogRepository catalogRepository;

    @Operation(summary = "获取所有板块名称", description = "{{ base_url }}/api/catalog/queryAllName")
    @GetMapping(value = "/queryAllName")
    public ResponseEntity<?> query(){

        List<Catalog> catalogList = catalogRepository.findAll();
        if (ObjectUtils.isEmpty(catalogList)) {
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }

        return ResponseEntity.ok(catalogList);
    }
}
